<template>
    <div>
        <van-sticky>
            <van-nav-bar title="商品订单" left-text="返回" left-arrow @click-left="() => { $router.push('/home/cart') }" />
        </van-sticky>
        <div v-for="item in dd">
            <van-card :num="item.number" :price="item.goods.goods_price" :title="item.goods.goods_name"
                class="goods-card">
                <template #thumb>
                    <van-image
                        :src="item.goods.goods_big_logo ? item.goods.goods_big_logo : 'https://ts4.cn.mm.bing.net/th?id=OIP-C.ygQGtHfTu-yKG2FEomqXSwHaHa&w=249&h=250&c=8&rs=1&qlt=90&o=6&dpr=1.3&pid=3.1&rm=2'" />
                </template>
            </van-card>
        </div>
        <van-submit-bar :price="pda.totalPrice*100" button-text="去支付" @submit="onSubmit" />
    </div>
</template>

<script setup>
import { showToast } from 'vant'
import { ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { orderApi, payApi } from '../../request/api'
import { useCounterStore } from '../../stores/counter'
const store = useCounterStore()
const route = useRoute()
const router = useRouter()
const dd = ref([])
const pda = ref({
    orderId: '',
    subject: '',
    totalPrice: 0
})

orderApi(route.params.id).then(res => {
    pda.value = {
        orderId: res.data.data.orderId,
        subject: res.data.data.product_code,
        totalPrice: res.data.data.totalPrice
    }
    let oda = store.carts || []
    let gid = res.data.data.goods.map(item => +item.goods_id)
    oda = oda.filter(item => {
        return gid.includes(+item.goods.goods_id)
    })
    dd.value = oda
})
const onSubmit=()=>{
    payApi(pda.value).then(res=>{
        window.open(res.data.data,'_blank')
    })
}

</script>

<style lang="scss" scoped></style>